package org.ihelpuoo.orm.parser;

import org.ihelpuoo.parser.token.CharChecker;
import org.ihelpuoo.parser.token.InvalidCharException;

public class FieldEndlChecker implements CharChecker
{
	private boolean	prevIsSlash;

	public FieldEndlChecker()
	{
		prevIsSlash = false;
	}

	public int doCheck(int c) throws InvalidCharException
	{
		if (c == (int)'\\')
		{
			if (prevIsSlash)
			{
				prevIsSlash = false;
				return c;
			}
			else
			{
				prevIsSlash = true;
				return IGNORE_IT;
			}
		}

		if (prevIsSlash)
		{
			if ((int)'\\' == c || (int)';' == c)
			{
				prevIsSlash = false;
				return c;
			}
			else
				throw new InvalidCharException("Only support [\\][;] after '\\'");
		}
		if (c == ';')
			return MATCHED;
		return c;
	}

}
